package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {
	/**
	 * 添加分类
	 *
	 * @param category
	 */
	@Insert("insert into category(type,name,sort,status,create_time,update_time,create_user,update_user) values " +
		"(#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
	void addCategory(Category category);
	
	/**
	 * 修改信息
	 *
	 * @param category
	 */
	void putCategory(Category category);
	
	/**
	 * 分页查询
	 *
	 * @param categoryPageQueryDTO
	 * @return
	 */
	Page<Category> getCategory(CategoryPageQueryDTO categoryPageQueryDTO);
	
	/**
	 * 根据id删除分类
	 *
	 * @param id
	 */
	@Delete("delete from category where id = #{id}")
	void deleteCategory(Long id);
	
	@Select("select * from category where id = #{id}")
	Category getCategoryId(Long id);
	
	@Select("select count(*) from category where sort = #{sort}")
	Integer getCategorySort(Integer sort);
	
	/**
	 * 根据类型查找
	 *
	 * @param type
	 * @return
	 */
	List<Category> getCategoryType(Integer type);
}
